class PantallasController < ApplicationController
  # GET /pantallas
  # GET /pantallas.json
  def index
    @pantallas = Pantalla.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json=> @pantallas }
    end
  end

  # GET /pantallas/1
  # GET /pantallas/1.json
  def show
    @pantalla = Pantalla.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render :json=> @pantalla }
    end
  end

  # GET /pantallas/new
  # GET /pantallas/new.json
  def new
    @pantalla = Pantalla.new
    @controladores = obtener_controladores

    respond_to do |format|
      format.html # new.html.erb
      format.json { render :json=> @pantalla }
    end
  end

  # GET /pantallas/1/edit
  def edit
    @pantalla = Pantalla.find(params[:id])
  end

  # POST /pantallas
  # POST /pantallas.json
  def create
    @pantalla = Pantalla.new(params[:pantalla])

    respond_to do |format|
      if @pantalla.save
        format.html { redirect_to @pantalla, :notice=> 'Pantalla was successfully created.' }
        format.json { render :json=> @pantalla, :status=> :created, :location=> @pantalla }
      else
        format.html { render :action=> "new" }
        format.json { render :json=> @pantalla.errors,:status=> :unprocessable_entity }
      end
    end
  end

  # PUT /pantallas/1
  # PUT /pantallas/1.json
  def update
    @pantalla = Pantalla.find(params[:id])

    respond_to do |format|
      if @pantalla.update_attributes(params[:pantalla])
        format.html { redirect_to @pantalla, :notice=> 'Pantalla was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render :action=> "edit" }
        format.json { render :json=> @pantalla.errors, :status=> :unprocessable_entity }
      end
    end
  end

  # DELETE /pantallas/1
  # DELETE /pantallas/1.json
  def destroy
    @pantalla = Pantalla.find(params[:id])
    @pantalla.perfiles_pantalla.destroy_all
    @pantalla.destroy

    respond_to do |format|
      format.html { redirect_to pantallas_url }
      format.json { head :no_content }
    end
  end
end
